/*
 * Project: Sudoku Explainer
 * Copyright (C) 2006-2007 Nicolas Juillerat
 * 
 * Project: Sudoku Hint Engine for Android
 * Copyright (C) 2010-2013 Emanuel Moecklin
 * 
 * Available under the terms of the Lesser General Public License (LGPL)
 */
package com.onegravity.sudoku.solver.rules;

import com.onegravity.sudoku.solver.HintResource;
import com.onegravity.sudoku.solver.R;
import com.onegravity.sudoku.solver.accumulator.HintsAccumulator;
import com.onegravity.sudoku.solver.accumulator.StopHintProductionException;
import com.onegravity.sudoku.solver.core.DirectHintProducer;
import com.onegravity.sudoku.solver.data.Cell;
import com.onegravity.sudoku.solver.data.Grid;

/**
 * Returns a random solved digit
 */
public class BruteForceProducer implements DirectHintProducer {

	private Grid solvedGrid;

	public BruteForceProducer(Grid solvedGrid) {
		this.solvedGrid = solvedGrid;
	}

	@Override
	public void getHints(Grid grid, HintsAccumulator accu) throws StopHintProductionException, InterruptedException {
		for (boolean cellFound=false; !cellFound && solvedGrid!=null; ) {
			int x = (int) Math.round(Math.random()*8);
			int y = (int) Math.round(Math.random()*8);
			Cell cell = grid.getCell(x, y);
			if (cell.isEmpty()) {
				accu.add(new BruteForceHint(cell, solvedGrid.getCell(x, y).getValue()));
				cellFound = true;
			}
		}
	}

    @Override
	public String getProducerName() {
		return HintResource.getString(R.string.producer_brute_force);
	}

}